package com.shenma2009.netty.server;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2023/7/4 0004 9:43
 */

import java.io.IOException;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/vehicle")
public class VehicleWebSocketServer {

    @OnMessage
    public void onMessage(String message, Session session) throws IOException {
        // 处理接收到的位置数据
        System.out.println("Received message from client: " + message);

        // 将位置数据发送给其他连接的客户端
        for (Session client : session.getOpenSessions()) {
            if (client.isOpen() && !client.equals(session)) {
                client.getBasicRemote().sendText(message);
            }
        }
    }
}
